﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AcsCommon;
using System.Data;

namespace YiShi.Class
{
    public class Question : DbObject, IGuide
    {
        private GuideLink[] guideLinks;
        public string Body
        {
            get
            {
                return dr["Body"];
            }
            set
            {
                dr["Body"] = value;
            }
        }
        public string Type
        {
            get
            {
                return dr["Type"];
            }
            set
            {
                dr["Type"] = value;
            }
        }
        public string Answer
        {
            get
            {
                return dr["Answer"];
            }
            set
            {
                dr["Answer"] = value;
            }
        }
        public string Scores
        {
            get
            {
                return dr["Scores"];
            }
            set
            {
                dr["Scores"] = value;
            }
        }

        public Question(DbAccess db)
            : base(db, "Admin.Question")
        {
        }
        public override void Update()
        {
            base.Update("Admin.Question");
        }
        public GuideLink[] GetGuideLinks()
        {
            if (String.IsNullOrEmpty(this.Id))
                throw new Exception("The id of the question is null!");
            if (this.guideLinks == null)
            {
                string sql = Sql.Format("select * from GuideLink where (PreGuideId = '{0}') order by Answer", this.Id);
                DataTable dt = this.db.QueryDataTable(sql);
                this.guideLinks = new GuideLink[dt.Rows.Count];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];
                    this.guideLinks[i] = new GuideLink(this.db);
                    dr.FillObject(this.guideLinks[i]);
                }
            }
            return this.guideLinks;
        }
    }
}
